/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dp1.pucp.Logistica.Vista;

import com.dp1.pucp.Modelo.Clases.*;
import com.dp1.pucp.Util.Validaciones;

import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JFrame;
/**
 *
 * @author daniek
 */
public class LineaPedidoCompraGUI extends javax.swing.JDialog {
    
    /**
     * Creates new form UsuarioGUI
     * 
     * 
     */
     private JFrame padre;
     public Almacen almacen = new Almacen();
     public Tipoproducto tipoProducto = new Tipoproducto();
     public Lineapedidocompra lineaPedido = new Lineapedidocompra();
    
    public LineaPedidoCompraGUI(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        txtCodPedido.setVisible(false);
        txtCodTipo.setVisible(false);
        setLocationRelativeTo(null);
    }
    
    public JFrame getPadre(){ return padre; }

    public void setFormUsuario(Tipoproducto u,String cod){
        
        if(cod!=null){
        String num=cod.substring(3, 11);
        int numero=Integer.parseInt(num);
        
        txtCodPedido.setText(String.valueOf(numero));
        }
        if (u!=null){
              txtCodTipo.setText(String.valueOf(u.getIdtipoproducto()));
              txtProducto.setText(u.getNombre());
              lblCantidad.setText(u.getUnidades());
              
//            txtNombre.setText(u.getNombre());

//            
            tipoProducto=u;
        }
    }
    
    public void setFormUsuario(Lineapedidocompra u,String cod){
        
        if(cod!=null){
            String num=cod.substring(3, 11);
            int numero=Integer.parseInt(num);
        
            txtCodPedido.setText(String.valueOf(numero));
        }
        if (u!=null){
              txtCantidad.setText(String.valueOf(u.getCantidad()));
              txtProducto.setText(u.getTipoproducto().getNombre());
              txtCodTipo.setText(String.valueOf(u.getTipoproducto().getIdtipoproducto()));
              //lblCantidad.setText(u.getUnidades());
              
//            txtNombre.setText(u.getNombre());
//            txtEspLibre.setText(u.getEspacioLibre().toString());
//            txtEspTotal.setText(String.valueOf(u.getEspacioTotal()));
//            txtEspUtiliz.setText(u.getEspacioUtilizado().toString());
//            txtDescripcion.setText(u.getDescripcion().toString());
//            
            //tipoProducto=u;
        }
    }
    
    public String getCantidad(){
        return txtCantidad.getText().trim();
    }      
    
    public String getNombre(){
        return txtProducto.getText().trim();
    }      
    
    public String getCodTipoProducto(){
        return txtCodTipo.getText().trim();
   }
    
    public String getCodPedido(){
        return txtCodPedido.getText().trim();
   }

//    
//    public String getDescripcion(){
//        return txtDescripcion.getText().trim();
//    }  
//    
//    public int getTipo(){
//        return cmbTipo.getSelectedIndex();
//    }
//    
//    public String getEspUtilizado(){
//        return txtEspUtiliz.getText().trim();
//    }
    
//    public void mostrarAviso(String msn){
//        Validaciones.mostrarMensajeAvisoVal(msn);   
//    }
//    public void mostrarError(String msn){
//        Validaciones.mostrarMensajeErrorVal(msn);           
//    }
//    public int solicitarConfirmacion(String msn){
//        return Validaciones.solicitarConfirmacionVal(msn);
//    }    
    
    
  
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jRadioButton1 = new javax.swing.JRadioButton();
        joanel = new javax.swing.JPanel();
        btnGuardar = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        txtCantidad = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtProducto = new javax.swing.JTextField();
        btnBuscar = new javax.swing.JButton();
        txtCodTipo = new javax.swing.JTextField();
        txtCodPedido = new javax.swing.JTextField();
        lblCantidad = new javax.swing.JLabel();

        jRadioButton1.setText("jRadioButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Buscar Materia Prima");

        joanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Ubuntu", 0, 15))); // NOI18N

        btnGuardar.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/save.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.setBorderPainted(false);
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        btnLimpiar.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/clear.png"))); // NOI18N
        btnLimpiar.setText("Limpiar");
        btnLimpiar.setBorderPainted(false);
        btnLimpiar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnLimpiar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        btnCancelar.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancel.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.setBorderPainted(false);
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        txtCantidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCantidadKeyTyped(evt);
            }
        });

        jLabel4.setText("Producto");

        jLabel7.setText("Cantidad");

        txtProducto.setEnabled(false);

        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/buscarChico.png"))); // NOI18N
        btnBuscar.setBorderPainted(false);

        txtCodTipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCodTipoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout joanelLayout = new javax.swing.GroupLayout(joanel);
        joanel.setLayout(joanelLayout);
        joanelLayout.setHorizontalGroup(
            joanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(joanelLayout.createSequentialGroup()
                .addGroup(joanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(joanelLayout.createSequentialGroup()
                        .addGap(159, 159, 159)
                        .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(joanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(joanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtCodPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(joanelLayout.createSequentialGroup()
                                .addComponent(txtCodTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(6, 6, 6)
                                .addGroup(joanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel4))))
                        .addGap(18, 18, 18)
                        .addGroup(joanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(joanelLayout.createSequentialGroup()
                                .addComponent(txtProducto)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(24, 24, 24))
                            .addGroup(joanelLayout.createSequentialGroup()
                                .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(63, Short.MAX_VALUE))
        );
        joanelLayout.setVerticalGroup(
            joanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(joanelLayout.createSequentialGroup()
                .addComponent(txtCodPedido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addGroup(joanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBuscar)
                    .addComponent(txtCodTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(joanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addGroup(joanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnGuardar)
                    .addComponent(btnLimpiar)
                    .addComponent(btnCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(joanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(joanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(32, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtCodTipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCodTipoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCodTipoActionPerformed

    private void txtCantidadKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCantidadKeyTyped
        // TODO add your handling code here:
        String car = txtCantidad.getText();
        if(car.length()>=6) evt.consume();        
        Validaciones.soloDigito(evt);
    }//GEN-LAST:event_txtCantidadKeyTyped

    
   public void LimpiarDatos(){
          txtCantidad.setText("");
          txtProducto.setText("");
    }
    
    public void addLimpiarListener(ActionListener ml){
        this.btnLimpiar.addActionListener(ml);
    }
        
    public void addGuardarListener(ActionListener ml){
        this.btnGuardar.addActionListener(ml);
    }
    
    public void addCancelarListener(ActionListener ml){
        this.btnCancelar.addActionListener(ml);
    } 
    
    public void addBuscarListener(ActionListener ml){
        this.btnBuscar.addActionListener(ml);
    }
    
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JPanel joanel;
    private javax.swing.JLabel lblCantidad;
    private javax.swing.JTextField txtCantidad;
    private javax.swing.JTextField txtCodPedido;
    private javax.swing.JTextField txtCodTipo;
    private javax.swing.JTextField txtProducto;
    // End of variables declaration//GEN-END:variables
}
